home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / SORTSTR.AML < prev    next >
Text File  |  1996-07-17  |  1KB  |  47 lines

  1. //--------------------------------------------------------------------
  2. // SORTSTR.AML
  3. // Sort a String, (C) 1993-1996 by nuText Systems
  4. //
  5. // This macro sorts characters in the first line of a marked block.
  6. // It may be useful for sorting symbols sets or analyzing character
  7. // frequencies in text.
  8. //
  9. // Usage:
  10. //
  11. // Select this macro from the Macro List (on the Macro menu), or run it
  12. // from the macro picklist <shift f12>.
  13. //--------------------------------------------------------------------
  14.  
  15. // compile time macros and function definitions
  16. include bootpath "define.aml"
  17.  
  18. // simple concatenation-type Quicksort for a string
  19. private function qsort (s)
  20.   n = length s
  21.   if n < 2 then
  22.     return s
  23.   end
  24.   midvalue = s [(n + 1) / 2]
  25.   s [(n + 1) / 2] = s [1]
  26.   last = 1
  27.   for i = 2 to n do
  28.     if s [i] < midvalue then
  29.       last = last + 1
  30.       temp = s [last]  s [last] = s [i]  s [i] = temp
  31.     end
  32.   end
  33.   return (qsort s [2..last]) + midvalue + (qsort s [last + 1..n])
  34. end
  35.  
  36. // edit windows only
  37. if wintype? "edit" then
  38.   if getmarkbuf == getcurrbuf then
  39.     // sort and replace chars in the first line of the mark
  40.     ovltext (qsort (getmarktext)) (getmarkleft) (getmarktop)
  41.   else
  42.     msgbox "Block not marked in current edit window"
  43.   end
  44. else
  45.   msgbox "Edit windows only!"
  46. end
  47.